package com.ruoyi.onlinevideo.mapper;/**
 * @InterfaceName: MessageMapper
 * @Description:
 * @Author: YourName
 * @Date: 2023-04-14
 */

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.onlinevideo.domain.Message;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;

/**
 *@InterfaceName: MessageMapper
 *@Description:
 *@Author: lilirui
 *@Date: 2023-04-14
 */
@Mapper
public interface MessageMapper extends BaseMapper<Message> {
    @Select("SELECT uid FROM\t(SELECT DISTINCT uid,create_time\n" +
            "FROM\n" +
            "((SELECT DISTINCT receiver uid,content,create_time,update_time,create_by,update_by FROM message WHERE (sender = #{userId}) ORDER BY create_time DESC)\n" +
            "UNION\n" +
            "(SELECT sender uid ,content,create_time,update_time,create_by,update_by FROM message WHERE (receiver = #{userId}) ORDER BY create_time DESC)) a\n" +
            "ORDER BY create_time DESC) a\n" +
            "GROUP BY uid")
    ArrayList<Long> getUidHisList(Long userId);

    @Select("SELECT * FROM message where sender=#{userId} and receiver=#{uid}  or receiver=#{userId} and sender=#{uid} ORDER BY create_time DESC limit 1")
    Message getrecentmsg(@Param("userId") Long userId,@Param("uid") Long uid);
}
